import regTrees
from numpy import *

testMat = mat(eye(4))
print("testMat\n", testMat)
#尝试使用函数切分数据集
mat0 , mat1 = regTrees.binSplitDataSet(testMat,1,0.5)
print("mat0\n",mat0)
print("mat1\n",mat1)

#9.3.2  对应的是9-1的图
myDat = regTrees.loadDataSet('ex00.txt')
#print("myDat\n",myDat)
myMat = mat(myDat)
#print("myMat\n",myMat)
myTree = regTrees.createTree(myMat)
#print("myTree\n",myTree)	

#对应的是9-2的图
myDat = regTrees.loadDataSet('ex0.txt')
print("myDat\n",myDat)
myMat = mat(myDat)
print("myMat\n",myMat)
myTree = regTrees.createTree(myMat)
print("myTree\n",myTree)

############后剪枝测试####################
myTree = regTrees.createTree(myMat,ops=(0,1))
myDatTest = regTrees.loadDataSet('ex2test.txt')
myMat2Test = mat(myDatTest)
#执行剪枝
myTree2 = regTrees.prune(myTree,myMat2Test)
print("myTree2\n", myTree2)
##############后剪枝######################

##########模型树的生成测试###############
myMat2 = mat(regTrees.loadDataSet('exp2.txt'))
myTree = regTrees.createTree(myMat2,regTrees.modelLeaf,regTrees.modelErr,(1,10))
print("myTree\n",myTree)
###########################################


######9.6节树回归与标准回归的比较###到这继续不下去了，再看P173

